package com.inventive.jmscache.server;

import com.inventive.jmscache.server.hazelcast.DataSerializationHelper;

import javax.jms.JMSException;
import javax.jms.ObjectMessage;
import javax.jms.TextMessage;
import java.io.*;

/**
 * @author Grant Little <grant.little@coreservices.com.au>
 */
public class JmsCacheObjectMessage extends JmsCacheMessage implements ObjectMessage, Serializable {

    private Serializable object;

    public JmsCacheObjectMessage() {
    }

    public JmsCacheObjectMessage(Serializable object) {
        this.object = object;
    }

    @Override
    public Serializable getObject() throws JMSException {
        return object;
    }

    @Override
    public void setObject(Serializable object) throws JMSException {
        this.object = object;
    }

    @Override
    public void readData(DataInput dataInput) throws IOException {
        super.readData(dataInput);
        object = DataSerializationHelper.readSafeSerializable(dataInput);
    }

    @Override
    public void writeData(DataOutput dataOutput) throws IOException {
        super.writeData(dataOutput);
        DataSerializationHelper.writeSafeSerializable(dataOutput, object);
    }
}
